﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DomainInfoLib
{
    public class OrdinalRequesterWhile:IRequester
    {
        APIPool _APIPool;

        public RegisterInfo GetResponseFromAPI(string DomainName, APIPool the_APIPool)
        {
            _APIPool = the_APIPool;

            return GetResponseFromAPI(DomainName);
        }

        private RegisterInfo GetResponseFromAPI(string DomainName)
        {
            try
            {
                int i = 0;

                while (true)
                {
                    IWebAPI api = _APIPool[i];

                    RegisterInfo info = api.GetResponseByWebAPI(DomainName);

                    if (info != null)
                    {
                        return info;
                    }

                    i++;

                    if (i == _APIPool.Count)
                    {
                        i = 0;
                    }
                }

            }
            catch
            {
                return null;
            }

        }
    }
}
